<template>
    <div class="common_br" style="margin-top: 16px; border-bottom: 1px solid #dcdee2;">
        <div class="common_channel_title"
             style="margin: 0;padding: 0; font-size: 14px; display: flex;flex-flow: row nowrap;border-color: transparent;">
            <h2 style="min-width: 150px;">
                {{ getValue(form.elementName, dataDict.channelGradeLevel1ElementDict) }}
            </h2>
            <FormItem :label-width="0">
                <!--                <Input :value="pageParams[form.elementCode]" disabled placeholder style="width: 200px"/>-->
                <Input :value="form[form.elementCode]" disabled placeholder style="width: 200px"/>
            </FormItem>
            <FormItem
                :label-width="16"
                :prop="form.addScore"
            >
                <!--                <InputNumber v-model="formData[form.addScore]" placeholder style="width: 200px"/>-->
                <InputNumber v-model="formData[form.elementCode + '_addScore']" placeholder style="width: 200px"/>
            </FormItem>
        </div>
        <div class="common_content">
            <Row>
                <Col :lg="24" :xl="12" v-for="(item,index) in form.children" :key="index">
                    <div class="common-form-item">
                        <FormItem
                            v-if="item.dscode === '1'"
                            :label="getValue(item.elementName, dataDict.channelGradeElementDict) || item.elementName + ':'">
                            <InputNumber v-model="formData[item.elementCode]" style="width: 200px"/>
                        </FormItem>
                        <FormItem
                            v-else
                            :label="getValue(item.elementName, dataDict.channelGradeElementDict) || item.elementName + ':'">
                            <Input :value="item.elementStr" disabled placeholder style="width: 200px"/>
                        </FormItem>

                        <div class="result">
                            <span>计算结果:</span>
                            <!--                            <span v-if="item.dscode === '1'">{{-->
                            <!--                                    // getCalcRes(formData[item.elementCode], item.elementWeight)-->
                            <!--                                    // item[item.elementCode]-->
                            <!--                                    item.elementValue-->
                            <!--                                }}</span>-->
                            <!--                            <span v-else>{{ item.elementValue }}</span>-->
                            <span>{{ item.elementValue }}</span>
                        </div>
                    </div>
                </Col>
            </Row>
        </div>
    </div>
</template>

<script>
export default {
    // 个人信息
    name: 'ResultItem',
    data() {
        return {}
    },
    props: {
        formData: {
            type: Object,
            require: true
        },
        form: {
            type: Object,
            required: true,
        },
        dataDict: {
            type: Object,
            required: true,
        },
        pageParams: {
            type: Object,
            required: true,
        },
    },
    methods: {
        getValue(value, dict) {
            if (!value || !dict) return;
            for (let i = 0; i < dict.length; i++) {
                if (value === dict[i].value)
                    return dict[i].title
            }
            return '';
        },
        getCalcRes(code, weight) {
            if (isNaN(code)) {
                return 0;
            }
            return Number(code) * weight
        },
        getFormRes(form, pageParams) {
            let score = 0;
            Array.isArray(form.children) && form.children.forEach(item => {
                if (item.dscode === '1') {
                    score += this.getCalcRes(this.formData[item.elementCode], item.elementWeight)
                } else {
                    score += Number(pageParams[item.elementCode + 'Value'])
                }
            })
            return score;
        },
    }
}
</script>

<style lang="less">
.common-form-item {
    display: flex;
    flex-flow: row nowrap;
    justify-content: start;

    .result {
        line-height: 32px;

        span {
            padding-left: 16px;
        }
    }

    .ivu-form-item-content {
        width: 200px;
    }
}
</style>
